#include "print_output.h"
#include "stdint.h"
#include <dal_rtl8373_drv.h>
#include "print_rtt.h"
#include "mib.h"
void print_reg_value(void)
{
    uint32_t pData, address, sds_index, sds_page, sds_reg, bitmask, Rx_swap_64b66b, Tx_swap_64b66b;
    volatile rtk_api_ret_t rtk_ret;
    sds_index = 0x0;
    sds_page = 0x05;
    sds_reg = 0x0;
    bitmask = 0xFFFF;
    rtk_ret = dal_rtl8373_sds_regbits_read(sds_index, sds_page, sds_reg, bitmask, &pData);
    LOG_INFO("SDS_regbits_read:sds_index:%d,ads_page:0x%2X,sds_reg:0x%2X,bimask:0x%04X,value:0x%04X\r\n",
             sds_index, sds_page, sds_reg, bitmask, pData);
    sds_index = 0x0;
    sds_page = 0x06;
    sds_reg = 0x02;
    bitmask = 0xFFFF;
    dal_rtl8373_sds_regbits_read(sds_index, sds_page, sds_reg, bitmask, &pData);
    LOG_INFO("SDS_regbits_read:sds_index:%d,ads_page:0x%2X,sds_reg:0x%2X,bimask:0x%04X,value:0x%04X\r\n",
             sds_index, sds_page, sds_reg, bitmask, pData);
    address = 0x63e8;
    pData = 0;
    rtl8373_getAsicReg(address, &pData);
    LOG_INFO("rtl8373_getAsicReg:adds:0x%04X,value:0x%04X\r\n", address, pData);

    address = 0x63F8;
    pData = 0;
    rtl8373_getAsicReg(address, &pData);
    LOG_INFO("rtl8373_getAsicReg:adds:0x%04X,value:0x%04X\r\n", address, pData);

    address = 0x6418;
    pData = 0;
    rtl8373_getAsicReg(address, &pData);
    LOG_INFO("rtl8373_getAsicReg:adds:0x%04X,value:0x%04X\r\n", address, pData);
}
#define RTK_STAT_PORT_TYPE_MAX 104
static const char *tbl[RTK_STAT_PORT_TYPE_MAX] = {
    [0] = "ifInOctets_H",
    [1] = "ifInOctets_L",
    [2] = "ifOutOctets_H",
    [3] = "ifOutOctets_L",
    [4] = "ifInUcastPkts_H",
    [5] = "ifInUcastPkts_L",
    [6] = "ifInMulticastPkts_H",
    [7] = "ifInMulticastPkts_L",
    [8] = "ifInBroadcastPkts_H",
    [9] = "ifInBroadcastPkts_L",
    [10] = "ifOutUcastPkts_H",
    [11] = "ifOutUcastPkts_L",
    [12] = "ifOutMulticastPkts_H",
    [13] = "ifOutMulticastPkts_L",
    [14] = "ifOutBroadcastPkts_H",
    [15] = "ifOutBroadcastPkts_L",

    [16] = "ifOutDiscards",
    [17] = "dot1dTpPortInDiscards",
    [18] = "dot3StatsSingleCollisionFrames",
    [19] = "dot3StatMultipleCollisionFrames",
    [20] = "dot3sDeferredTransmissions",
    [21] = "dot3StatsLateCollisions",
    [22] = "dot3StatsExcessiveCollisions",
    [23] = "dot3StatsSymbolErrors",
    [24] = "dot3ControlInUnknownOpcodes",
    [25] = "dot3InPauseFrames",
    [26] = "dot3OutPauseFrames",
    [27] = "etherStatsDropEvents",
    [28] = "tx_etherStatsBroadcastPkts",
    [29] = "tx_etherStatsMulticastPkts",
    [30] = "tx_etherStatsCRCAlignErrors",
    [31] = "rx_etherStatsCRCAlignErrors",
    [32] = "tx_etherStatsUndersizePkts",
    [33] = "rx_etherStatsUndersizePkts",
    [34] = "tx_etherStatsOversizePkts",
    [35] = "rx_etherStatsOversizePkts",
    [36] = "tx_etherStatsFragments",
    [37] = "rx_etherStatsFragments",
    [38] = "tx_etherStatsJabbers",
    [39] = "rx_etherStatsJabbers",
    [40] = "tx_etherStatsCollisions",
    [41] = "tx_etherStatsPkts64Octets",
    [42] = "rx_etherStatsPkts64Octets",
    [43] = "tx_etherStatsPkts65to127Octets",
    [44] = "rx_etherStatsPkts65to127Octets",
    [45] = "tx_etherStatsPkts128to255Octets",
    [46] = "rx_etherStatsPkts128to255Octets",
    [47] = "tx_etherStatsPkts256to511Octets",
    [48] = "rx_etherStatsPkts256to511Octets",
    [49] = "tx_etherStatsPkts512to1023Octets",
    [50] = "rx_etherStatsPkts512to1023Octets",
    [51] = "tx_etherStatsPkts1024to1518Octets",
    [52] = "rx_etherStatsPkts1024to1518Octets",
    /* 53 空白，留 NULL */
    [54] = "rx_etherStatsUndersizedropPkts",
    [55] = "tx_etherStatsPkts1519toMaxOctets",
    [56] = "rx_etherStatsPkts1519toMaxOctets",
    [57] = "tx_etherStatsPktsOverMaxOctets",
    [58] = "rx_etherStatsPktsOverMaxOctets",
    [59] = "tx_etherStatsPktsFlexibleOctetsSET1",
    [60] = "rx_etherStatsPktsFlexibleOctetsSET1",
    [61] = "tx_etherStatsPktsFlexibleOctetsCRCSET1",
    [62] = "rx_etherStatsPktsFlexibleOctetsCRCSET1",
    [63] = "tx_etherStatsPktsFlexibleOctetsSET0",
    [64] = "rx_etherStatsPktsFlexibleOctetsSET0",
    [65] = "tx_etherStatsPktsFlexibleOctetsCRSET0C",
    [66] = "rx_etherStatsPktsFlexibleOctetsCRSET0C",
    [67] = "lengthFieldError",
    [68] = "falseCarrieimes",
    [69] = "underSizeOctets",
    [70] = "framingErrors",
    [71] = "rxMacDiscards",
    [72] = "rxMacIPGShortDropRT",
    /* 73、74 空白，留 NULL */
    [75] = "dot1dTpLearnedEntryDiscards",
    [76] = "egrQueue7DropPktRT",
    [77] = "egrQueue6DropPktRT",
    [78] = "egrQueue5DropPktRT",
    [79] = "egrQueue4DropPktRT",
    [80] = "egrQueue3DropPktRT",
    [81] = "egrQueue2DropPktRT",
    [82] = "egrQueue1DropPktRT",
    [83] = "egrQueue0DropPktRT",
    [84] = "egrQueue7OutPktRT",
    [85] = "egrQueue6OutPktRT",
    [86] = "egrQueue5OutPktRT",
    [87] = "egrQueue4OutPktRT",
    [88] = "egrQueue3OutPktRT",
    [89] = "egrQueue2OutPktRT",
    [90] = "egrQueue1OutPktRT",
    [91] = "egrQueue0OutPktRT",
    [92] = "TxGoodCnt_H",
    [93] = "TxGoodCnt_L",
    [94] = "RxGoodCnt_H",
    [95] = "RxGoodCnt_L",
    [96] = "RxErrorCnt",
    [97] = "TxErrorCnt",
    [98] = "TxGoodCnt_phy_H",
    [99] = "TxGoodCnt_phy_L",
    [100] = "RxGoodCnt_phy_H",
    [101] = "RxGoodCnt_phy_L",
    [102] = "RxErrorCnt_phy",
    [103] = "TxErrorCnt_phy",
};
const char *rtk_stat_port_name(int id)
{
    if (id < 0 || id >= RTK_STAT_PORT_TYPE_MAX)
        return "UNKNOWN";
    const char *s = tbl[id];
    return s ? s : "UNKNOWN";
}
void print_count_value(void)
{
    volatile rtk_api_ret_t rtk_ret;
    rtk_uint64 pCntr_port4, pCntr_port7 = 0;
    rtk_port_t port_id;
    rtk_stat_port_type_t cntr_idx;

    for (cntr_idx = ifInOctets_H; cntr_idx <= (uint8_t)TxErrorCnt_phy; cntr_idx++)
    {
        port_id = 4;
        if ((cntr_idx == 53) || (cntr_idx == 73) || (cntr_idx == 74))
        {
            continue;
        }
        port_id = 4;
        rtk_ret = rtk_stat_port_get(port_id, cntr_idx, &pCntr_port4);
        port_id = 7;
        rtk_ret = rtk_stat_port_get(port_id, cntr_idx, &pCntr_port7);
        LOG_INFO("ret:%d,port 4-%s:%d\n", rtk_ret, rtk_stat_port_name(cntr_idx), pCntr_port4);
        LOG_INFO("ret:%d,port 7-%s:%d\n", rtk_ret, rtk_stat_port_name(cntr_idx), pCntr_port7);
    }
}
